<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <!--<el-form-item label="企业ID" prop="companyId">-->
        <!--<el-input-->
          <!--v-model="queryParams.companyId"-->
          <!--placeholder="请输入企业ID"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="企业名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="人民币的总价值" prop="productPricermb">-->
        <!--<el-input-->
          <!--v-model="queryParams.productPricermb"-->
          <!--placeholder="请输入人民币的总价值"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="欧元的总价值" prop="productPriceeuro">-->
        <!--<el-input-->
          <!--v-model="queryParams.productPriceeuro"-->
          <!--placeholder="请输入欧元的总价值"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="人民币转欧元的汇率" prop="exchangeRate">-->
        <!--<el-input-->
          <!--v-model="queryParams.exchangeRate"-->
          <!--placeholder="请输入人民币转欧元的汇率"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="产品总价格" prop="productSum">-->
        <!--<el-input-->
          <!--v-model="queryParams.productSum"-->
          <!--placeholder="请输入产品总价格"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable size="small">
          <el-option label="待处理" value="0" />
          <el-option label="已核对" value="1" />
          <el-option label="交易完成" value="2" />
          <el-option label="交易失败" value="3" />
        </el-select>
      </el-form-item>

      <el-form-item label="下单时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <!--<el-form-item label="操作员id" prop="operaterId">-->
        <!--<el-input-->
          <!--v-model="queryParams.operaterId"-->
          <!--placeholder="请输入操作员id"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="primary"-->
          <!--plain-->
          <!--icon="el-icon-plus"-->
          <!--size="mini"-->
          <!--@click="handleAdd"-->
          <!--v-hasPermi="['order:orderPrice:add']"-->
        <!--&gt;新增</el-button>-->
      <!--</el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['order:orderPrice:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['order:orderPrice:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['order:orderPrice:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderPriceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="订单id" align="center" prop="orderId" />-->
      <!--<el-table-column label="企业ID" align="center" prop="companyId" />-->
      <el-table-column label="企业名称" align="center" prop="companyName" />
      <!--<el-table-column label="人民币的总价值" align="center" prop="productPricermb" />-->
      <!--<el-table-column label="欧元的总价值" align="center" prop="productPriceeuro" />-->
      <el-table-column label="订单总金额" align="center" prop="productSum" />
      <el-table-column label="汇率" align="center" prop="exchangeRate" />

      <!--<el-table-column label="订单状态" align="center" prop="status" >-->
        <!--<el-select v-model="status"  clearable size="small">-->
          <!--<el-option label="待处理" value="0" />-->
          <!--<el-option label="已核对" value="1" />-->
          <!--<el-option label="交易完成" value="2" />-->
          <!--<el-option label="交易失败" value="3" />-->
        <!--</el-select>-->
      <!--</el-table-column>-->
      <el-table-column prop="status" label="订单状态" align="center"  :formatter="statusFormat" width="80"></el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="操作员id" align="center" prop="operaterId" />-->
      <!--<el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['order:orderPrice:edit']"
          >修改</el-button>
          <el-button
            type="text"
            size="small"
            icon="el-icon-view"
            @click="handlePreview(scope.row)"
            v-hasPermi="['order:orderPrice:detail']"
          >订单详情</el-button>
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-delete"-->
            <!--@click="handleDelete(scope.row)"-->
            <!--v-hasPermi="['order:orderPrice:remove']"-->
          <!--&gt;删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <!--<el-col :span="24">-->
            <!--<el-form-item label="企业ID" prop="companyId"  v-show="false">-->
              <!--<el-input v-model="form.companyId" placeholder="请输入企业ID" />-->
            <!--</el-form-item>-->
          <!--</el-col>-->
          <el-col :span="24">
            <el-form-item label="企业名称" prop="companyId">
              <el-input v-model="form.companyName" placeholder="请输入企业名称" :disabled="true"  />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品总价格" prop="productSum">
              <el-input v-model="form.productPricermb" placeholder="产品总价格" :disabled="true" />
            </el-form-item>
          </el-col>
          <!--<el-col :span="12">-->
            <!--<el-form-item label="欧元总价值" prop="productPriceeuro">-->
              <!--<el-input v-model="form.productPriceeuro" placeholder="请输入欧元的总价值" />-->
            <!--</el-form-item>-->
          <!--</el-col>-->
          <el-col :span="12">
            <el-form-item label="汇率" prop="exchangeRate">
              <el-input v-model="form.exchangeRate" placeholder="请输入人民币转欧元的汇率" :disabled="true" />
            </el-form-item>
          </el-col>
          <!--<el-col :span="12">-->
            <!--<el-form-item label="产品总价格" prop="productPricermb">-->
              <!--<el-input v-model="form.productSum" placeholder="请输入产品总价格" />-->
            <!--</el-form-item>-->
          <!--</el-col>-->
          <el-col :span="12">
            <el-form-item label="订单状态">
              <el-select v-model="form.status" placeholder="请选择订单状态" clearable size="small">
                <el-option label="待处理" value="0" />
                <el-option label="已核对" value="1" />
                <el-option label="交易完成" value="2" />
                <el-option label="交易失败" value="3" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
          <el-col :span="12"></el-col>
          <el-col :span="12"></el-col>
          <el-col :span="12"></el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <!--<el-form-item label="操作员id" prop="operaterId">-->
          <!--<el-input v-model="form.operaterId" placeholder="请输入操作员id" />-->
        <!--</el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderPrice, getOrderPrice, delOrderPrice, addOrderPrice, updateOrderPrice, exportOrderPrice } from "@/api/order/orderPrice";

export default {
  name: "OrderPrice",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息表格数据
      orderPriceList: [],
      // 日期范围
      dateRange: [],
      // 菜单状态数据字典
      statusOptions: [{dictValue: "0",dictLabel: "待处理" },{dictValue: "1",dictLabel: "已核对" },{dictValue: "2",dictLabel: "交易完成" },{dictValue: "3",dictLabel: "交易失败" }],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        companyName: null,
        productPricermb: null,
        productPriceeuro: null,
        exchangeRate: null,
        productSum: null,
        status: null,
        operaterId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        companyId: [
          { required: true, message: "企业ID不能为空", trigger: "blur" }
        ],
        companyName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        productPricermb: [
          { required: true, message: "人民币的总价值不能为空", trigger: "blur" }
        ],
        productPriceeuro: [
          { required: true, message: "欧元的总价值不能为空", trigger: "blur" }
        ],
        exchangeRate: [
          { required: true, message: "人民币转欧元的汇率不能为空", trigger: "blur" }
        ],
        productSum: [
          { required: true, message: "产品总价格不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单信息列表 */
    getList() {
      this.loading = true;
      listOrderPrice(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.orderPriceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        companyId: null,
        productPricermb: null,
        productPriceeuro: null,
        exchangeRate: null,
        productSum: null,
        status: "0",
        createTime: null,
        updateTime: null,
        operaterId: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 菜单状态字典翻译
    statusFormat(row, column) {

      return this.selectDictLabel(this.statusOptions, row.status);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getOrderPrice(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单信息";
      });
    },
    /** 查看订单详情 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getOrderPrice(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateOrderPrice(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderPrice(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$confirm('是否确认删除订单信息编号为"' + orderIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrderPrice(orderIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有订单信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOrderPrice(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
